package com.demo.gulimall.product.controller;

import com.demo.gulimall.common.utils.R;
import com.demo.gulimall.product.entity.Category;
import com.demo.gulimall.product.service.CategoryService;
import com.demo.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Chen Yuan
 * @create 2023-05-24  13:53
 */
@RestController
public class CategoryController {
	@Autowired
	private CategoryService categoryService;


	@GetMapping("/list/tree")
	public R list(){
		List<Category> categories = categoryService.listWithTree();
		return R.ok(categories);
	}

	@GetMapping("/list/level1")
	public R getLevel1Categorys(){
		List<Category> level1Categorys = categoryService.getLevel1Categorys();
		return R.ok(level1Categorys);
	}

	@GetMapping("/list/catalogjson")
	public R getCatalogJson(){
		Map<String, List<Catelog2Vo>> catalogJsonFromDb = categoryService.getCategoriesJsonFromDb();
		return R.ok(catalogJsonFromDb);
	}


}
